package com.dili.dd.gpi.util.velocity;

import com.dili.dd.gpi.enums.BaseEnumInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * velocity 遍历枚举值的toolbox
 * Created by zhaoYuan on 2015/3/25.
 */
public class EnumToolBox {

    public EnumToolBox() {
    }

    private static Logger logger = LoggerFactory.getLogger(EnumToolBox.class);

    public BaseEnumInterface[] listValues(String className) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        logger.info("枚举类型{}",className);
        System.out.println("class name :" + className);
        Class<?> clazz = Class.forName(className);
        if (clazz.isEnum()) {
            Method valuesMethod = clazz.getMethod("values");
            BaseEnumInterface[] values = (BaseEnumInterface[])valuesMethod.invoke(null);
            return values;
        }
        return null;
    }

    public BaseEnumInterface[] getColor(String param){
        System.out.println("print out Red success !");
        return new BaseEnumInterface[2];
    }
}
